function build_tabs() {
	var tabs = new Array();
	var tab = {};
	tab.initialized = false;
	tab.id = 'tab_div_sign';
	tab.type = 'sign';
	tab.name = 'Sign';
	tabs.push(tab);
	tab = {};
	tab.initialized = false;
	tab.id = 'tab_div_stat';
	tab.type = 'stat';
	tab.name = 'Statistics';
	tabs.push(tab);
	tab = {};
	tab.initialized = false;
	tab.id = 'tab_div_options';
	tab.type = 'option';
	tab.name = 'Options';
	tabs.push(tab);
	var managed_modules = dao.loadManagedModules();
	for (var i in managed_modules) {
		tab = {};
		tab.initialized = false;
		tab.id = get_mm_tab_id(managed_modules[i]);
		tab.type = 'manage';
		tab.name = get_mm_tab_name(managed_modules[i]);
		tabs.push(tab);
	}
	var div_tab = document.getElementById("div_tab");
	for (var i in tabs) {
		tab = tabs[i];
		var div = document.createElement("label");
		div.className = 'unselected_tab';
		div.width = '100';
		div.innerText = tab.name;
		div.id = tab.id;
		div.tab = tab;
		div.onclick = switch_tab;
		div_tab.appendChild(div);
	}
	var debug_div = document.createElement("span");
	div_tab.appendChild(debug_div);
	var debug = document.createElement("input");
	debug.type = 'checkbox';
	debug.id = 'debug';
	debug_div.appendChild(debug);
	var debug_label = document.createElement("label");
	debug_label.innerText = "Debug";
	debug_div.appendChild(debug_label);

}

function switch_tab() {
	var tab = event.srcElement;
	var tabs = document.getElementById("div_tab").children;
	var contents = document.getElementById("div_content").children;
	var content = null;
	for (var i = 0; i < tabs.length - 1; i++) {
		tabs[i].className = 'unselected_tab';
		contents[i].style.display = "none";
		if (tab == tabs[i]) {
			content = contents[i];
			contents[i].style.display = "block";
		}
	}
	tab.className = 'selected_tab';
	if (tab.tab.initialized == false) {
		switch (tab.tab.type) {
			case 'sign':
				init_sign_div();
				break;
			case 'manage':
				init_managed_div(tab.tab.id, content);
				break;
			case 'stat':
				init_statistics();
				break;
			case 'option':
				init_options();
				break;
		}
		tab.tab.initialized = true;
	}
}

window.onload = function() {
	build_tabs();
	init_managed_modules_divs();
	log_div = document.getElementById('status');
	var event = null;
	if (document.createEvent) {
		event = document.createEvent("HTMLEvents");
		event.initEvent("click", true, true);
		event.target = document.getElementById("div_tab").firstElementChild;
		document.getElementById("div_tab").firstElementChild.dispatchEvent(event);
	} else {
		event = document.createEventObject();
		event.eventType = 'click';
		document.getElementById("div_tab").firstElementChild.fireEvent("on" + event.type, event);
	}
}
